<template>
  <div class="content-wrap">
    <van-nav-bar title="聊天信息" left-arrow @click-left="$router.go(-1)">
    </van-nav-bar>
    <user-msg-box isLink avatar-size="large" :userMsg="info" :to="{name: 'friendDetail', params: {id: $route.params.id}}"
                  style="margin-top: .4rem"></user-msg-box>

    <van-cell-group class="checkGroup">
      <van-switch-cell v-model="disturbChecked" title="消息免打扰" @change="editSetting('disturbChecked')"/>
      <van-switch-cell v-model="topChecked" title="置顶聊天" @change="editSetting('topChecked')"/>
    </van-cell-group>

    <van-cell-group class="checkGroup">
      <van-cell title="清空聊天记录" is-link @click="clearChatRecord"/>
    </van-cell-group>
  </div>
</template>

<script>
  import Socket from '../../utils/socket'

  export default {
    name: 'chatSetting',
    data () {
      return {
        disturbChecked: false,
        topChecked: false,
        info: {}
      }
    },
    methods: {
      getFriendInfo () {
        Socket.sendData('getFriendsInfo', { fid: this.$route.params.id }).then(res => {
          if (res.action === 20002 && res.data) {
            this.info = res.data
          }
        })
      },
      editSetting (type) {
        let flag = this[type] ? 1 : 2
        if (type === 'disturbChecked') {
          Socket.sendData('FriendsDoNotice', { status: flag, fid: this.$route.params.id })
        } else if (type === 'topChecked') {
          Socket.sendData('FriendsDoPlus', { status: flag, fid: this.$route.params.id })
        }
      },
      clearChatRecord () {
        this.$dialog.confirm({
          message: '确认清空聊天记录吗？'
        }).then(() => {
          Socket.sendData('DeleteChatData', { fid: this.$route.params.id })
        }).catch(() => {
        })
      }
    },
    created () {
      this.getFriendInfo()
    }
  }
</script>

<style scoped lang="scss">
</style>
